﻿namespace QMVnSoft.DAL
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmFileDataAccess
    {
        public DataTable GetTable()
        {
            DataTable table2;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmFile_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return table2;
        }

        public DataTable GetTable(object pi_Order, int pi_Type)
        {
            DataTable table2;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", pi_Order), new SqlParameter("p_Type", pi_Type) };
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            DataTable dataTable = new DataTable();
            SqlDataAdapter adapter = new SqlDataAdapter();
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmFile_Fields_Get";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                adapter.SelectCommand = command;
                adapter.Fill(dataTable);
                AppDataAccess.CloseConnection(eZConnection);
                table2 = dataTable;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return table2;
        }

        public int SaveRow(DataRow row)
        {
            int num;
            SqlParameter[] values = new SqlParameter[] { new SqlParameter("p_Stt", row["Stt"]), new SqlParameter("p_FieldList", row["FieldList"]), new SqlParameter("p_FieldOrder", row["FieldOrder"]), new SqlParameter("p_FilterFieldList", row["FilterFieldList"]), new SqlParameter("p_FilterType", row["FilterType"]), new SqlParameter("p_MatchCase", row["MatchCase"]), new SqlParameter("p_StartPos", row["StartPos"]), new SqlParameter("p_CodeNested", row["CodeNested"]), new SqlParameter("p_MaxRows", row["MaxRows"]), new SqlParameter("p_EachWord", row["EachWord"]), new SqlParameter("p_FreeFields", row["FreeFields"]), new SqlParameter("p_Result", SqlDbType.BigInt) };
            values[11].Direction = ParameterDirection.Output;
            values[11].SqlDbType = SqlDbType.Int;
            SqlConnection eZConnection = AppDataAccess.AppConnection;
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "DmFile_Save";
                command.CommandType = CommandType.StoredProcedure;
                command.Connection = eZConnection;
                command.Parameters.AddRange(values);
                command.ExecuteNonQuery();
                AppDataAccess.CloseConnection(eZConnection);
                num = (int) values[11].Value;
            }
            catch (Exception exception)
            {
                throw new NotSupportedException("Invalid expression", exception);
            }
            return num;
        }
    }
}

